package com.seckill.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seckill.demo.entity.Orders;
import com.seckill.demo.mapper.OrdersMapper;
import com.seckill.demo.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Slf4j
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
    @Override
    public int descType(Long id, int type) {
        return baseMapper.descType(id, type);
    }

    @Override
    public Orders getOrdersById(Long id) {
        return baseMapper.getById(id);
    }

    @Override
    @Transactional
    public int testInsert1(Long id) throws InterruptedException {
        Orders orders = new Orders();
        orders.setId(id);
        orders.setGoodId(id);
        orders.setGoodsName("test 1");
        orders.setType(Math.toIntExact(id));
        orders.setUserId(id);

        log.info("baseMapper.insert(orders)===:{}", baseMapper.insert(orders));
        Thread.sleep(5000);
        log.info("baseMapper.deleteById(id)===:{}", baseMapper.deleteById(id));
        return 0;
    }

    @Override
    @Transactional
    public int testInsert2(Long id) {
        Orders orders = new Orders();
        orders.setId(id);
        orders.setGoodId(id);
        orders.setGoodsName("test 2");
        orders.setType(Math.toIntExact(id));
        orders.setUserId(id);

        baseMapper.insert(orders);
        log.info("baseMapper.insert(orders)===:{}", baseMapper.insert(orders));
        return 0;
    }
}